package com.example.graduatetest.fragments;


import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.graduatetest.R;
import com.example.graduatetest.databinding.FragmentMeBinding;
import com.example.graduatetest.view.model.MeViewModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment {
    private MeViewModel meViewModel;
    private FragmentMeBinding binding;

    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if(meViewModel == null){
            meViewModel = new MeViewModel();
        }
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_me, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        meViewModel = ViewModelProviders.of(requireActivity()).get(MeViewModel.class);
        meViewModel.init(requireActivity(),binding);
        binding.setMeViewModel(meViewModel);
        binding.setLifecycleOwner(this);
    }
}
